export {}
//对象的形状
interface Speakable{
    speak():void;
    name?:string;//?表示可选
  }

  let speakMan:Speakable={
    name:'xx',
    speak() {
    },
  }

  //行为的抽象
  //同名的接口可以写多个，类型会自动合并
  interface Speakable{
    speak():void
  }
  interface Eatable{
    eat():void
  }
//类实现接口
  class Person implements Speakable,Eatable{
     name?: string | undefined;
      speak(): void {
          throw new Error("Method not implemented.");
      }
      eat(): void {
          throw new Error("Method not implemented.");
      }
    
  }
//任意属性[key:string]:any
interface Person2{
    readonly id:number;
    name:string;
    [key:string]:any
}
let p:Person2={
    id:1,
    name:'xx',
    age:10,
    home:'1'
}

//接口的继承
interface Speakable{
    speak():void
}
interface SpeakChinese extends Speakable{
    speakChinese():void
}
class Chinese implements SpeakChinese{
    speakChinese(): void {
        throw new Error("Method not implemented.");
    }
    speak(): void {
        throw new Error("Method not implemented.");
    }
}

interface Person3{
    readonly id:number
}
let p3:Person3 = {
    id:1
}

//函数类型的接口
interface Discount{
    (prize:number):number
}
const discount:Discount = (prize:number):number=>{
    return prize*.8
}

//可索引接口
//对数组和对象进行约束
interface User{
    [index:number]:string
}
let user:User={
    0:'0',1:'1',2:'2'
}
let arr:User =['1','2','3']

//如何用接口约束类
interface Speakable{
    speak():void
}
//构造函数类型
class Animal{
    constructor(public name:string){

    }
}
//如果是修饰普通函数
//加上new之后 就是用来描述类的构造函数类型
//没有
interface WitchNameClass{
  new(name:string):any
}
let wc:WitchNameClass = Animal
function createAnimal(clazz:WitchNameClass,name:string){
    return new clazz(name)
}
let a = createAnimal(Animal,'zhufeng')
console.log(a.name);
